<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div class="md-padding">

    <div ng-if="vm.loadingHiveSchemas">
        <span class="hint">{{"views.hql-editor.Iad" | translate}}</span>
        <md-progress-linear class="md-accent" md-mode="indeterminate"></md-progress-linear>
      </div>
      <div id="hqlEditorContainer">
        <span class="md-input-label">{{"views.hql-editor.EQ" | translate}}</span>
        <div id="codemirror-editor" class="hql-editor" ui-codemirror="{ onLoad : vm.codemirrorLoaded }" ng-model="vm.sql" ui-codemirror-opts="vm.codemirrorOptions">
        </div>
      </div>
      <span class="hint">{{vm.metadataMessage}}</span>
      <div layout="row" layout-fill layout-align="space-between center">
        <md-button class="md-primary md-raised" ng-disabled="vm.sql == ''" ng-click="vm.query()" ng-if="vm.allowExecuteQuery">
          {{"views.hql-editor.ExecuteQ" | translate}}
        </md-button>
    <span flex></span>
    <md-button ng-if="vm.allowFullscreen" class="md-raised" ng-click="vm.fullscreen()">
            {{"views.hql-editor.FS" | translate}}
    </md-button>
</div>
</div>
<div ng-if="vm.allowDatabaseBrowse" class="layout-padding-top">
    <div class="md-title">{{"views.hql-editor.BH" | translate}}</div>
    <md-input-container>
      <label>{{"views.hql-editor.Database" | translate}}</label>
      <md-select ng-model="vm.browseDatabaseName">
        <md-option ng-repeat="databaseName in vm.databaseNames" value="{{::databaseName}}">
          {{::databaseName}}
        </md-option>
      </md-select>
    </md-input-container>
    <md-input-container>
      <label>{{"views.hql-editor.Table" | translate}}</label>
      <md-select ng-model="vm.browseTableName" ng-change="vm.browseTable()">
        <md-option ng-repeat="(tableName,fields) in vm.databaseMetadata[vm.browseDatabaseName]" value="{{::tableName}}">
          {{::tableName}}
        </md-option>
      </md-select>
    </md-input-container>
  </div>
  <md-progress-linear class="md-accent" md-mode="indeterminate" ng-if="vm.executingQuery"></md-progress-linear>
  <div class="browse-results">
    <div id="{{vm.tableId}}"
         flex
         browser-height
         browser-height-scroll-y="false"
         browser-height-offset="500">
    </div>
  </div>
</div>
